﻿using System;


namespace HAVNet.Core
{
    public class Lazy
    {
        static object lockLazyInst = new object();

        public static T inst<T>(T t) where T : new ()
        {
            if (null == t)
                t = new T();

            return t;
        }

        public static string toStringNN<T>(T t, string @default) 
        {
            return toStringNN<T>(t, @default, "");  
        }

        public static string toStringNN<T>(T t, string @default, string sAdd)
        {
            if (t is string)
                return ((null == t || "" == t.ToString()) ? @default : t.ToString() + sAdd);
            else
                return (null == t ? @default : t.ToString() + sAdd);
        }

        public static T instTS<T>(T t) where T : new()
        {
            lock (lockLazyInst)
                return inst(t);
        }
    }
}
